#### II Replication ####
### purpose: replicating table 3 and 4 ####
# installing packages ----

list.of.packages = c('estimatr', 'stargazer', 'MASS')
new.packages <- list.of.packages[!(list.of.packages %in% 
                                     installed.packages()[,"Package"])]

if(length(new.packages)) install.packages(new.packages)

# loading packages ----

suppressPackageStartupMessages(
  {
    library(estimatr)
    library(stargazer)
    library(MASS)
  }
)

# loading in data ----
h2_dt <- readRDS("~/data/rep_data2_usglc.RDS")

# Table 3 ----
res1 <- lm(total_leg ~ usglc, data=h2_dt)

res2 <- lm(total_leg ~ usglc + as.factor(cong), data=h2_dt)

res3 <- glm.nb(total_leg ~ usglc, data=h2_dt)

res4 <- glm.nb(total_leg ~ usglc + as.factor(cong), data=h2_dt)

stargazer(res1, res2, res3, res4,
          model.names =TRUE, 
          header=FALSE, 
          keep=c("usglc"), 
          covariate.labels=c("usglc lobby"), 
          align=T, 
          font.size="scriptsize", 
          omit.stat=c("f", "ser", "bic", "aic", "ll", "theta"), 
          column.sep.width="0pt", 
          dep.var.labels.include=FALSE, 
          title = "Results for Hypothesis 2", 
          omit.table.layout="l",
          type="latex", 
          add.lines = list(c("cong FE", "N", "Y", "N", "Y" )))

# Table 4 ----
res5 <- lm(republican ~ usglc, data=h2_dt)

res6 <- lm(republican ~ usglc + as.factor(cong), data=h2_dt)

res7 <- glm.nb(republican ~ usglc, data=h2_dt)

res8 <- glm.nb(republican ~ usglc + as.factor(cong), data=h2_dt)

stargazer(res5, res6, res7, res8,
          model.names =TRUE, 
          header=FALSE, 
          keep=c("usglc"), 
          covariate.labels=c("usglc lobby"), 
          align=T, 
          font.size="scriptsize", 
          omit.stat=c("f", "ser", "bic", "aic", "ll", "theta"), 
          column.sep.width="0pt", 
          dep.var.labels.include=FALSE, 
          title = "Results for Hypothesis 2 (The number of Republican (co)sponsors)", 
          omit.table.layout="l",
          type="latex", 
          add.lines = list(c("cong FE", "N", "Y", "N", "Y" )))